package com.check.operation.fragment;

import android.widget.ListView;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.check.operation.CheckApplication;
import com.check.operation.R;
import com.check.operation.base.BaseFragment;
import com.check.operation.model.Gfpoints;
import com.check.operation.model.Gftype;
import com.check.operation.model.MessagRe;
import com.check.operation.model.Ssroom;
import com.check.operation.service.HjgyAdapter;
import com.szj.util.HttpUtil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.App;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.List;

/**
 * 呼叫工友
 */
@EFragment(R.layout.fragment_hjgy)
public class HjgyFragment extends BaseFragment {

    public static final String TAG = "ssfj";

    @App CheckApplication checkApp;

    @ViewById ListView ssfjs;

    List<Ssroom> ssrooms;
    HjgyAdapter hjgyAdapter;
    List<Gftype> gftypes;

    @AfterViews
    public void init() {
        ssrooms = checkApp.getSsrooms();
        refreshMsg("呼叫工友");
        String action = "workpoint/gettypes";
        String rs = HttpUtil.get(action);
        MessagRe<List<Gftype>> ars = JSONObject.parseObject(rs, new TypeReference<MessagRe<List<Gftype>>>() {
        });
        if ("success".equals(ars.message.code)) {
            gftypes = ars.value;
            this.hjgyAdapter = new HjgyAdapter(getLayoutInflater(), checkApp.getUserRe().getUser(), ssrooms, gftypes);
            ssfjs.setAdapter(hjgyAdapter);
            hjgyAdapter.notifyDataSetChanged();
            for (Gftype gftype : gftypes) {
                action = "workpoint/getpoints?TypeCode=" + gftype.TypeCode;
                rs = HttpUtil.get(action);
                MessagRe<List<Gfpoints>> sssd = JSONObject.parseObject(rs, new TypeReference<MessagRe<List<Gfpoints>>>() {});
                Gfpoints gp = new Gfpoints();
                gp.Name = "---请选择---";
                gp.Code = "0";
                sssd.value.add(0, gp);
                gftype.gfpoints = sssd.value;
            }
        }
    }
    
    @Override
    public void onGetBarValue(String paramString) {}
}
